import request from '@/utils/request'
import {
  loginForm,
  loginResponseData,
  userInfoResponseData,
  logoutResponseData,
} from '@/api/user/type'

enum API {
  LOGIN_URL = '/admin/acl/index/login',
  USERINFO_URL = '/admin/acl/index/info',
  LOGOUT_URL = '/admin/acl/index/logout',
}

export const reqLogin = (data: loginForm) => {
  // post泛型中, 仅指定T则返回的是AxiosResponse包装数据, 此处指定T和R, 使直接返回业务数据, 下同
  return request.post<loginResponseData, loginResponseData>(API.LOGIN_URL, data)
}

// 箭头函数简写
export const reqUserInfo = () =>
  request.get<userInfoResponseData, userInfoResponseData>(API.USERINFO_URL)

export const reqLogout = () =>
  request.post<logoutResponseData, logoutResponseData>(API.LOGOUT_URL)
